# -*- coding: utf-8 -*-
# -文件说明——正则表达式:re库-
# @Time    : 2019/7/16 9:50
# @Author  : hwx
# @Email   : @163.com
# @File    : WS04demo1.py
# @Software: PyCharm
import re
# PY+  无穷表达式
# PY[^PY]{0,10}  PY开头，后续存在不多于10个字符，后续字符不能有P和Y
'''
^[A-Za-z]+$
^[A-Za-z0-9]+$
^-?\d+$
^[0-9]*[1-9][0-9]*$
[1-9]\d{5}
[\u4e00_\u9fa5]
\d+{1,3}.\d+.\d+.\d+
[1-9]?\d
1\d{2}
2[0-4]\d
25[0-5]

r'[1-9]\d{5}'
'''


def fun1():
    """
raw string ：原生字符串：不包含转义符，加个r,如：r'[1-9]\d{5}'
string :必须用转义符：[1-9]\\d{5}
    """
    match = re.search(r'[1-9]\d{5}', 'bit 100081,18723,123676')
    if match:
        print('长度:', len(match.group()))
        for i in range(len(match.group())):
            print(match.group())

# fun1()


def fun2():
    strdemo = 'bit 100081,18723,123676'
    strdemo2 = '100081,bit,18723,123676'

    match = re.match(r'[1-9]\d{5}', strdemo2)   # strdemo时match为空，匹配开头
    if not match:
        print('match为空：', match is None)
    else:
        print('match不为空：', match is not None)
        print(match.group())


# fun2()


def fun3():
    strdemo3 = '100081,bit,18723,123676'
    ls  = re.findall(r'[1-9]\d{5}', strdemo3)
    print('ls:',ls)
# fun3()
def fun4():
    strdemo3 = '100081,bit,18723,123676'
    # sli = re.split(r'[1-9]\d{5}', strdemo3)
    sli = re.split(r'[1-9]\d{5}', strdemo3,maxsplit=1)
    print(sli)
# fun4()


def fun5():
    strdemo3 = '100081,bit,18723,123676'
    it = re.finditer(r'[1-9]\d{5}', strdemo3)
    for i in it:
        if i:
            print(i.group())
# fun5()


def fun6():
    strdemo3 = '100081,bit,18723,123676'
    it = re.sub(r'[1-9]\d{5}', '待匹配的字符串',strdemo3)
    print(it)
# fun6()


def fun7():
    """
面对对象用法，前面是函数式用法:一次编译，速度快
    """
    strdemo3 = '100081,bit,18723,123676'
    pat = re.compile(r'[1-9]\d{5}')
    rst = pat.search(strdemo3)



def fun8():
    """
raw string ：原生字符串：不包含转义符，加个r,如：r'[1-9]\d{5}'
string :必须用转义符：[1-9]\\d{5}
    """
    str1 = '1.平时嗓门大的小张在回答问题时声音小，老师批评说：“声音这么小，难道你是蚊子么？”全班哄堂大笑，该老师做法（）'
    str2 = '3:safsafa阿萨德撒多（）'
    str3 = ""
    print(str3 == '')
    match = re.match(r'[1-9]+..*', str1)
    print(match)
    if not match:
        print('match为空：', match is None)
    else:
        print('match不为空：', match is not None)
        print(match.group())

fun8()